﻿using System.Collections.Generic;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Sql.Configuration
{
	public class SqlDatabaseData : DatabaseData
	{
		///<summary>
		/// Initializes a new instance of the <see cref="SqlDatabase"/> class with a connection string and a configuration
		/// source.
		///</summary>
		///<param name="connectionStringSettings">The <see cref="ConnectionStringSettings"/> for the represented database.</param>
		///<param name="configurationSource">The <see cref="IConfigurationSource"/> from which additional information can 
		/// be retrieved if necessary.</param>
		public SqlDatabaseData(ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource) : base(connectionStringSettings, configurationSource)
		{
		}

		/// <summary>
		/// Creates a <see cref="TypeRegistration"/> instance describing the <see cref="SqlDatabase"/> represented by 
		/// this configuration object.
		/// </summary>
		/// <returns>A <see cref="TypeRegistration"/> instance describing a database.</returns>
		public override IEnumerable<TypeRegistration> GetRegistrations()
		{
			yield return new TypeRegistration<Database>(
				() => new SqlDatabase(
					ConnectionString,
					Container.Resolved<IDataInstrumentationProvider>(Name)))
			{
				Name = Name,
				Lifetime = TypeRegistrationLifetime.Transient
			};
		}
	}
}